package com.example.drools_study.demo2.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;

/**
 * @Author: 郭浩伟 qq:912161367
 * @Date: 2022/11/17 0017 7:18
 * @Description: 个人所得税预扣率表（居民个人工资、薪金所得预扣预缴适用）
 */
@AllArgsConstructor
@Getter
public enum WithholdingTaxRateEnum {
    /**
     * 级数
     */
    one(36_000, "0.03", 0),
    two(144_000, "0.10", 2520),
    three(300_000, "0.20", 16920),
    four(420_000, "0.25", 31920),
    five(660_000, "0.30", 52920),
    six(960_000, "0.35", 85920),
    seven(960_000, "0.45", 181920),
    ;

    /**
     * 全年累计预扣预缴应纳税所得额
     */
    private Integer taxableIncome;
    /**
     * 税率，如0.03
     */
    private String taxRate;
    /**
     * 速算扣除数
     */
    private Integer quickDeduction;

    /**
     * 根据【应纳税所得额】得到含对应的【税率】和【速算扣除数】的枚举值
     *
     * @param actualTaxableIncome
     * @return
     */
    public static WithholdingTaxRateEnum getInfoByIncome(BigDecimal actualTaxableIncome) {
        if(null == actualTaxableIncome){
            return null;
        }
        for (WithholdingTaxRateEnum value : WithholdingTaxRateEnum.values()) {
            if(actualTaxableIncome.compareTo(BigDecimal.valueOf(value.getTaxableIncome())) <= 0){
                return value;
            }
        }
        return seven;
    }
}
